home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 300_01 / ttst_v2d.c < prev    next >
Text File  |  1989-12-28  |  5KB  |  143 lines

  1. /*
  2.       TITLE:   Token array demo;
  3.        DATE:   4/09/1989;
  4. DESCRIPTION:   "Tests all token array functions";
  5.     VERSION:   2.04;
  6.    FILENAME:   TTST_V2D.C;
  7.    SEE-ALSO:   MAT_V2D.H;
  8. */
  9.  
  10. /*   (C) COPYRIGHT BY JOHN J. HUGHES III, 1989  */
  11.  
  12. #include "mat_v2D.h";
  13. #include <stdlib.h>
  14. #include <string.h>
  15.  
  16. int cmp (void *a, void *b);
  17.  
  18. main()
  19.  
  20. {
  21. unsigned int   r,c,t,DEBUG,tsz,rw,cl;
  22. struct fmat  *numbers;
  23. struct tmat  *nums,*misc,*appnd;
  24. FILE  *FN;
  25.  
  26.    printf("Enter DEBUG level => ");scanf("%d",&DEBUG);
  27.  
  28.    if (DEBUG>0) puts("mtcnt(nums.dta):1");
  29.       mtcnt("nums.dta",&r,&c,&t);
  30.    if (DEBUG>0) printf(
  31.       "for nums.dta : rows %d,cols %d,and token size %d read.\n",r,c,t);
  32.    if (DEBUG>0) puts("tdim(nums):2");
  33.       tdim(nums,r,c,t);
  34.    if (DEBUG>0) printf(
  35.       "for nums array : rows %d,cols %d,and token size %d allocated.\n",
  36.             no_rows(nums),no_cols(nums),token_sz(nums));
  37.    if (DEBUG>0) puts("tdim(nums):3");
  38.       mtget("nums.dta",nums);
  39.    if (DEBUG>0) puts("mtcnt(misc.dta):1");
  40.       mtcnt("misc.dta",&r,&c,&t);
  41.    if (DEBUG>0) printf(
  42.       "for misc.dta : rows %d,cols %d,and token size %d read.\n",r,c,t);
  43.    if (DEBUG>0) puts("tdim(misc):4");
  44.       tdim(misc,r,c,t);
  45.    if (DEBUG>0) printf(
  46.       "for misc array : rows %d,cols %d,and token size %d allocated.\n",
  47.        no_rows(misc),no_cols(misc),token_sz(misc));
  48.    if (DEBUG>0) puts("mtread(misc):5");
  49.       mtread("misc.dta",misc);
  50.    if (DEBUG>3) { puts("mtdump(nums):6");
  51.       mtdump(nums); }
  52.    if (DEBUG>3) { puts("mtdump(misc):7");
  53.       mtdump(misc); }
  54.    if (DEBUG>0)printf("Floating point value -- %f\n",tf(misc,5,1,4));
  55.    if (DEBUG>0)printf("Floating point value -- %f\n",tf(misc,5,2,4));
  56.    if (DEBUG>0) puts("ft used to place value in misc array:8");
  57.       ft(misc,3,2,993.98,80,10,3);
  58.    if (DEBUG>0)printf("Integer point value -- %d\n",ti(misc,5,3,4));
  59.    if (DEBUG>0) puts("it used to place value in misc array:9");
  60.       it(misc,3,1,666,80,10);
  61.    if (DEBUG>0)printf("string value -- %s\n",ts(misc,3,0,3));
  62.    if (DEBUG>0) puts("tt used to place value in misc array:10");
  63.       tt(misc,4,2,"n_entry",80,10);
  64.    if (DEBUG>3) { puts("mtdump(misc):11");
  65.       mtdump(misc); }
  66.    if (DEBUG>0)puts("tdim(apnd):12");
  67.         tsz=token_sz(misc);
  68.         rw=no_rows(misc)+1;
  69.         cl=no_cols(misc);
  70.  
  71.      { unsigned nnni;
  72.         if ( (int) (((appnd)=(struct tmat *)malloc(sizeof(struct tmat))) == 0)
  73.         ) error (YES,9,rw,cl);
  74.         if ( (int) ((((appnd)->t)=(char *) calloc((rw)*(cl)*(tsz+1),
  75.                                                 sizeof(char)))==0)
  76.         ) error (YES,9,rw,cl);
  77.         if ( (int) ((((appnd)->n_toks) = (unsigned *)calloc((rw),
  78.                                                 sizeof(unsigned)))==0)
  79.         ) error (YES,9,rw,cl);
  80.         ((appnd)->n_rows)=(rw); ((appnd)->n_cols)=(cl);
  81.         ((appnd)->tok_sz)=(tsz)+1;  ((appnd)->n_recs)=0;
  82.         for(nnni=0;nnni<(rw);nnni++) (appnd)->n_toks[nnni]=0;
  83.         for(nnni=0;nnni<(rw)*((cl));nnni++) (appnd)->t[nnni*(tsz+1)]=NULL; }
  84.  
  85. /*        tdim(appnd,(no_rows(misc)+1),no_cols(misc),tmp);  */
  86.  
  87.     if (DEBUG>0)puts("mtcpy nums to misc:13");
  88.       mtcpy(misc,appnd);
  89.    if (DEBUG>0)puts("mtapnd third row of nums to appnd:14");
  90.       mtapnd(appnd,nums,2);
  91.    if (DEBUG>3) { puts("mtdump appnd:15");
  92.       mtdump(appnd); }
  93.    if (DEBUG>0)puts("flcreat output.dta file:16");
  94.       flcreat("output.dta",FN);
  95.    if (DEBUG>0)puts("Output a centered TITLE to output.dta:18");
  96.       msc(FN,"TITLE");
  97.    if (DEBUG>0)puts("Output a right justified RIGHT to output.dta:19");
  98.       msr(FN,"RIGHT");
  99.    if (DEBUG>0)puts("Output a left justified LEFT to output.dta:20");
  100.       msl(FN,"LEFT");
  101.    if (DEBUG>0)puts("Output phrase and float value to output.dta:21");
  102.       msv(FN,"Value from appnd text matrix row 5, col 1",
  103.          tf(appnd,5,1,4));
  104.    if (DEBUG>0)puts("Output phrase and token to output.dta:21");
  105.       mst(FN,"Token from appnd matrix row 5, col 0",
  106.               t(appnd,5,0));
  107.    if (DEBUG>3) puts("Output 4 cols of appnd to output.dta:22");
  108.       mtput(FN,appnd,"c1 c2 c3 c4 c5","c1 c2 c3 c4 c5",70,7);
  109.    if (DEBUG>3) puts("Sort 2nd column and re-output");
  110.         qsort(t(appnd,0,0),no_recs(appnd),(no_cols(appnd)*
  111.          token_sz(appnd)),cmp);
  112.       mtput(FN,appnd,"c1 c2 c3 c4 c5","c1 c2 c3 c4 c5",70,7);
  113.    if (DEBUG>0)puts("Close output.dta:23");
  114.       fclose(FN);
  115.    if (DEBUG>0)puts("Test tmtofm/read A.DTA into misc:24");
  116.       trel(misc);tdim(misc,4,4,TOK);mtget("a.dta",misc);
  117.    if (DEBUG>0)puts("Test tmtofm/fdim numbers array:25");
  118.       fdim(numbers,4,4);
  119.    if (DEBUG>0)puts("Test tmtofm/execute tmtofm:26");
  120.       tmtofm(numbers,misc);
  121.    if (DEBUG>9)  { puts("dump numbers");
  122.       mfdump(numbers); }
  123. }
  124.  
  125. int cmp (void *a, void *b)
  126.  
  127. {
  128. unsigned int   test;
  129. struct tmat *amat,*bmat;
  130.  
  131.    tdim(amat,1,5,10);
  132.    tdim(bmat,1,5,10);
  133.  
  134.     memcpy(t(amat,0,0),a,55);
  135.     memcpy(t(bmat,0,0),b,55);
  136.  
  137.    test = strcmp( t(amat,0,0) ,t(bmat,0,0) );
  138.    trel(amat);
  139.    trel(bmat);
  140.  
  141.    return(test);
  142. }
  143.